package com.yunlan.friendscenter.exception;

import com.yunlan.friendscenter.common.BaseResponse;
import com.yunlan.friendscenter.common.ErrorCode;
import com.yunlan.friendscenter.common.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Author: Wang
 * Date: 2022/5/2 20:07
 * 异常处理器(Aop)
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessExceptionHandler(BusinessException e){
      log.error("businessExceptionHandler:"+e.getMessage(),e);
      return ResultUtils.error(e.getCode(),e.getMessage(),e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeExceptionHandler(RuntimeException e){
      log.error("runtimeExceptionHandler:",e);
      return ResultUtils.error(ErrorCode.SYSTEM_ERROR,e.getMessage(),"");
    }

}
